import { useEffect, useState } from 'react';
import server from './../../utils/server/server';

export default (functionCode?: string) => {
  const [hasPrintConfiguration, setHasPrintConfiguration] = useState<boolean>(!!functionCode);

  useEffect(() => {
    (async () => {
      if (functionCode) {
        const res = await server('/bk/mid/fd/combineBirtModelAndForm', { moduleCode: 'workflow', functionCode });

        if (res) {
          setHasPrintConfiguration(res?.rows?.[0]?.isFromPrintConfiguration);
        }
      }
    })();
  }, []);

  return hasPrintConfiguration;
};
